package main.剑指OfferⅠ;

public class Day13 {
    public static void main(String[] args) {
        System.out.println("剑指Offer21.调整数组顺序使奇数位于偶数前面");
        System.out.println("剑指Offer57.和为s的两个数");
        System.out.println("剑指Offer58-Ⅰ.翻转单词顺序");
    }
}

class Offer21{
    public int[] exchange(int[] nums) {
        int[] result=new int[nums.length];
        int left=0,right= nums.length-1;
        for (int i=0;i< nums.length;i++){
            if (nums[i]%2==0){
                result[right]=nums[i];
                right--;
            }else {
                result[left]=nums[i];
                left++;
            }
        }
        return result;
    }
}

class Offer57{
    public int[] twoSum(int[] nums, int target) {
        int[] result=new int[2];
        int left=0,right=nums.length-1;
        while (left<right){
            if (nums[left]+nums[right]==target){
                result[0]=nums[left];
                result[1]=nums[right];
                break;
            }else if (nums[left]+nums[right]<target) left++;
            else right--;
        }
        return result;
    }
}

class Offer58_Ⅰ{
    public String reverseWords(String s) {
        String[] strs=s.split(" ");
        StringBuffer result=new StringBuffer();
        for (int i= strs.length-1;i>=0;i--){
            if (strs[i].length()==0) continue;
            result.append(strs[i]);
            result.append(" ");
        }
        if (result.length()>0) result.deleteCharAt(result.length()-1);
        return result.toString();
    }
}